<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                手机号码：<input type="text" name="mobile"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="realName"/>
                            </li>
                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<script th:src="@{/js/md5.js}"></script>
<script th:inline="javascript">

    var prefix = ctx + "sso/staff";

    $(function () {
        queryUserList();
    });

    function queryUserList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "用户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '用户ID'
                },
                {
                    field: 'mobile',
                    title: '手机号',
                    sortable: true
                },
                {
                    field: 'username',
                    title: '用户名称'
                },
                {
                    field: 'realName',
                    title: '真实姓名'
                },

                {
                    field: 'gender',
                    title: '性别',
                    formatter: function (value, row, index) {
                        if (row.gender == 0) {
                            return "女";
                        } else {
                            return "男";
                        }
                    }
                },
                {
                    field: 'deleted',
                    title: '用户可用',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (row.roleId != 1) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="staffIdByRoleList(\'' + row.id + '\')"></i>用户角色</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="staffIdByAreaList(\'' + row.id + '\')"></i>用户园区</a> ');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="selectStaffTicket(\'' + row.id + '\')"></i>用户ticket</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="updatePassword(\'' + row.id + '\')"><i class="fa fa-edit"></i>重置密码</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="disable(\'' + row.id + '\')"><i class="fa fa-remove"></i>停用</a> ');

                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }
            ]
        };
        $.table.init(options);
    }

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.deleted == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* sso用户管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要停用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "deleted": 1});
        })
    }

    /* sso用户管理-启用 */
    function enable(id) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "deleted": 0});
        })
    }

    /* sso用户重置密码 */
    function updatePassword(id) {
        $.modal.confirm("确认要重置密码为【Abc@123456】吗？", function () {
            $.operate.post(prefix + "/updatePassword", {"id": id, "password": md5("Abc@123456")});
        })
    }

    /* sso用户Ticket */
    function selectStaffTicket(id) {
        var url = prefix + '/selectStaffTicket?staffId=' + id;
        $.modal.open("用户Ticket管理", url);
    }


    /* 角色列表 */
    function staffIdByRoleList(id) {
        var url = prefix + '/staffIdByRoleList?id=' + id;
        $.modal.openTab("用户角色列表", url);
    }

    /* 用户园区列表 */
    function staffIdByAreaList(id) {
        var url = prefix + '/staffIdByAreaList?id=' + id;
        $.modal.openTab("用户园区列表", url);
    }
</script>
</body>

</html>